/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package Bankmanagement;

import java.util.ArrayList;

/**
 *  use ArrayList to set the priority
 * @author ashongtical
 */
// import necessary packages

public class TaskManager {
    //use ArrayList to manage the data
    private ArrayList<String> highPriorityTasks;
    private ArrayList<String> lowPriorityTasks;

    public TaskManager() {
       //create new ArrayList object for priorities
        highPriorityTasks = new ArrayList<>();
        lowPriorityTasks = new ArrayList<>();
    }

    // Add a task
    public void addTask(String task) {
        if (task.contains("*")) {
            highPriorityTasks.add(task);
        } else {
            lowPriorityTasks.add(task);
        }
    }

    // Remove a task
    public void removeTask(String priority, int index) {
        if (priority.equalsIgnoreCase("high")) {
            if (index >= 0 && index < highPriorityTasks.size()) {
                highPriorityTasks.remove(index);
            }
        } else if (priority.equalsIgnoreCase("low")) {
            if (index >= 0 && index < lowPriorityTasks.size()) {
                lowPriorityTasks.remove(index);
            }
        }
    }

    // Change task priority
    // allows moving tasks between high and low priority lists
    public void changePriority(String priority, int index) {
        if (priority.equalsIgnoreCase("high")) {
            if (index >= 0 && index < highPriorityTasks.size()) {
                String task = highPriorityTasks.remove(index);
                lowPriorityTasks.add(task.replace("*", "").trim()); // 移除 * 标记
            }
        } else if (priority.equalsIgnoreCase("low")) {
            if (index >= 0 && index < lowPriorityTasks.size()) {
                String task = lowPriorityTasks.remove(index);
                highPriorityTasks.add(task + " *"); // 添加 * 标记
            }
        }
    }

    // Promote a high-priority task 
    //moves a high-priority task up in the list
    public void promoteTask(int index) {
        if (index > 0 && index < highPriorityTasks.size()) {
            String task = highPriorityTasks.remove(index);
            highPriorityTasks.add(index - 1, task);
        }
    }
    
//     list getters
    // Get high-priority tasks
    // return copies of the lists to avoid direct modification
    public ArrayList<String> getHighPriorityTasks() {
        return new ArrayList<>(highPriorityTasks);
    }

    // Get low-priority tasks
    // return copies of the lists to avoid direct modification
    public ArrayList<String> getLowPriorityTasks() {
        return new ArrayList<>(lowPriorityTasks);
    }

    // Display tasks
    public void displayTasks() {
        System.out.println("\nHigh Priority Tasks:");
        for (int i = 0; i < highPriorityTasks.size(); i++) {
            System.out.println(i + ". " + highPriorityTasks.get(i));
        }

        System.out.println("\nLow Priority Tasks:");
        for (int i = 0; i < lowPriorityTasks.size(); i++) {
            System.out.println(i + ". " + lowPriorityTasks.get(i));
        }
    }
}
